<template lang="html">
  <el-table :data="this.$store.getters.mylist.tableList" style="width: 100%">
    <el-table-column label="消耗品类型" prop="goodsClassifyName">
    </el-table-column>
    <el-table-column label="商品罗列" prop="c1" :formatter="dateFormatter">
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button-group>
          <el-button @click="handleDelete(scope.$index, scope.row)" type="danger" size="mini" icon="el-icon-delete"></el-button>
         <!--  <el-button @click="handleDelete(scope.$index, scope.row)" type="danger" size="mini" icon="el-icon-delete" v-if="scope.row.c1.length" disabled></el-button> -->
        </el-button-group>
      </template>
    </el-table-column>
  </el-table>
</template>
<script>
import { mapActions } from 'vuex'
import * as url from '../../../api/ygrapi.js'
export default {
  name: 'ETtable',
  components: {

  },
  data() {
    return {

    }
  },
  methods: {
    ...mapActions(['getTable', 'changePage','expend/opList','expend/getLists']),
    handleDelete(index, row) {
      console.log(index, row)
      if (row.c1[0].name) {
        this.$message({
          type: 'info',
          message: '该分类下已存在消耗品不可删除'
        })
      }else {
        this.$confirm(`是否删除${row.goodsClassifyName}?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this['expend/opList']([url.delCTData,{id:row.id}]).then(res=>{
              this.$store.commit('expend/message',{res:res,tt:this})
            }).catch(err=>{
              console.log(err)
            }).then(res=>{
              this['expend/getLists']([url.getCTData])
            })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
      }
    },
    dateFormatter(row,col){//过滤，格式化数组对象
      let arrName=[];
      if (row.c1) {
        row.c1.forEach(item=>{
        arrName.push(item.name)
      })
      }
      return arrName.join(',')
    }

  },
  created() {

  },
}

</script>
<style lang="less">
</style>
